﻿using Furion;
using Microsoft.Extensions.Hosting;
using OnWork.DataCenter.BLL.TaskScheduler;

namespace OnWork.DataCenter.BLL.HostedService
{
    public class ScheduleHostedService : IHostedService
    {
        private readonly TaskSchedulerBLL taskSchedulerBLL;

        public ScheduleHostedService()
        {
            taskSchedulerBLL = App.GetService<TaskSchedulerBLL>();
        }

        public async Task StartAsync(CancellationToken cancellationToken)
        {
            await Task.Factory.StartNew(async () =>
            {
                //延迟40s执行
                await Task.Delay(1000 * 30);
                await taskSchedulerBLL.UpdateJobs();
            });

            //throw new NotImplementedException();
            // await Task.CompletedTask;
        }

        public async Task StopAsync(CancellationToken cancellationToken)
        {
            await Task.CompletedTask;
            //throw new NotImplementedException();
        }
    }
}